from django.contrib import admin
from .models import Course, Lesson, CourseEnrollment


@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    """心理课程管理"""
    list_display = ['id', 'course_name', 'course_type', 'instructor', 'total_lessons', 'difficulty_level', 'is_free', 'is_active', 'created_at']
    list_filter = ['course_type', 'difficulty_level', 'is_free', 'is_active', 'created_at']
    search_fields = ['course_name', 'instructor', 'description']
    ordering = ['-created_at']


@admin.register(Lesson)
class LessonAdmin(admin.ModelAdmin):
    """课程课时管理"""
    list_display = ['id', 'course', 'lesson_number', 'lesson_title', 'duration_minutes', 'created_at']
    list_filter = ['course', 'created_at']
    search_fields = ['lesson_title', 'content', 'course__course_name']
    ordering = ['lesson_number']


@admin.register(CourseEnrollment)
class CourseEnrollmentAdmin(admin.ModelAdmin):
    """课程注册管理"""
    list_display = ['id', 'user', 'course', 'enrolled_at', 'progress', 'is_completed', 'completed_at']
    list_filter = ['is_completed', 'enrolled_at', 'completed_at']
    search_fields = ['user__username', 'course__course_name']
    date_hierarchy = 'enrolled_at'
    ordering = ['-enrolled_at']
